<?php
class Model {
	function __construct() {
		$this->db = new Database();
	}
	
	protected function existId($table_name, $col_name, $value) {
		$param = array(
			':value' => $value
		);
		
		$strQuery = 'SELECT * FROM ' . $table_name .  
                    'WHERE ' . $col_name . '=:value';
		$prepare = $this->db->prepare($strQuery);
		$prepare->execute($param);
		
		$count = $prepare->rowCount();
		if ($count > 0) {
			return true;
		}
		
		return false;
	}
	
	protected function randId($max = 20){
        $chars = 'abcdefghijklmnopqrstuvwxwz';
		$chars .= 'ABCDEFGHIJKLMNOPQRSTUVXWZ';
		$chars .= '0123456789_';
		
		$string = '';
        for($i = 0; $i < $max; $i++){
            $rand_key = mt_rand(0, strlen($chars));
            $string  .= substr($chars, $rand_key, 1);
        }
        return str_shuffle($string);
    }
}
